<?php
class loginControl extends Control{	
	//显示登录界面
	public function index(){
		C('DEBUG',0);
		if($this->rbac_is_login()){
			go('index/index');
		}
		$this->display();		
	}
	//实现登陆具体功能，配置用户session参数
	public function login(){	
		$username = $_POST['username'];
		$password = md5($_POST['password']);
		if ($this->rbac_user_login ( $username, $password, 'admin' )) {
			$db = M('user');			
			$time = time ();
			$uid = $_SESSION['user'];
			$userInfo = $db->field('style')->where('uid='.$uid)->find();
			$data['logintime'] = $time;
			$data['loginip'] = ip_get_client ();
			$data['uid'] = $uid;			
			$db->save ($data);
			$_SESSION ['loginip'] = ip_get_client ();
			$_SESSION ['logintime'] = date ( 'y-m-d h:s:i', $time );
			$_SESSION['style'] = $userInfo['style'];
			go ( "login/index" );
		}else{
			$this->error($this->error,'login/index');
		}
	}
	//显示验证码
	public function showCode(){
		$code = new code();
		$code->show();
	}
	//验证验证码
	public function checkCode(){
		if(strtoupper($_POST['code']) != $_SESSION['code']){
			echo 0;
		}else{
			echo 1;
		}	
	}	
}








?>